home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_315 / surf / scrnio.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  173 lines

  1. /* main program */
  2.  
  3. #include "scrnio.ih"
  4. #ifdef MANX
  5. #include <functions.h>
  6. #endif MANX
  7.  
  8. #include "scrndef.h"
  9. #include "scrnio.h"
  10. #include "gadgetdef.h"
  11. #include "menudef.h"
  12.  
  13. struct Screen *SurfScrn = NULL;
  14. struct Window *SurfWin = NULL;
  15. struct Window *CntrlWin = NULL;
  16. struct Window *GadWin = NULL;
  17. /*
  18.  * bit masks for waiting for signals
  19.  */
  20. short CntrlSigBit, SurfSigBit, GadSigBit;
  21. long SignalMask = 0;
  22.  
  23. struct RastPort *rp;
  24. struct ViewPort *vp;
  25.  
  26. struct Library *GfxBase = 0,
  27.                *IntuitionBase = 0;
  28.  
  29. int XOR = COMPLEMENT, /* so my other modules don't need to */
  30.     WRITE = JAM1;     /* include so many amiga includes */
  31.  
  32. int WinHOrig, WinVOrig;
  33. int WinFgCol;
  34. int ColorMax;
  35. int NumColors;
  36.  
  37. /*
  38.  * data structures needed to use amiga polygons routines
  39.  */
  40. static WORD PolyArea[5*5];
  41. static struct AreaInfo PolyInfo;
  42. static PLANEPTR PolyWorkSpace;
  43. static struct TmpRas PolyTmpRas;
  44.  
  45.  
  46.  
  47. static void ResetWinDat() {
  48.  
  49.     WinHOrig = SurfWinDef.Width >>1;
  50.     WinVOrig = SurfWinDef.Height >>1;
  51.  
  52.  
  53.     rp = SurfWin->RPort;
  54.     SetDrMd( rp,  JAM1 );
  55. }
  56.  
  57.  
  58.  
  59. /*
  60.  * open surface window/screen
  61.  */
  62. OpenSurf() {
  63.     NumColors = 1 << SurfScrnDef.Depth;
  64.     ColorMax = ( NumColors -1) * DitherLevels + 1;
  65.     WinFgCol = (NumColors - 1) & 0x1f;
  66.  
  67.     SurfScrnDef.BlockPen = ( WinFgCol *3) /4;
  68.     SurfScrnDef.DetailPen = WinFgCol>>2;
  69.  
  70.     SurfScrn = OpenScreen( &SurfScrnDef );
  71.     MenuSetColMap();
  72.     SurfWinDef.Screen = GadWinDef.Screen = SurfScrn;
  73.     SurfWinDef.Width = GadWinDef.Width = SurfScrnDef.Width;
  74.     SurfWinDef.Height = SurfScrnDef.Height - ButHeight;
  75.  
  76.     SurfWin = OpenWindow( &SurfWinDef );
  77.     GadWin = OpenWindow( &GadWinDef );
  78.     SurfSigBit = SurfWin->UserPort->mp_SigBit;
  79.     GadSigBit = GadWin->UserPort->mp_SigBit;
  80.     SignalMask = (1<<CntrlSigBit) | (1<<SurfSigBit)| (1<<GadSigBit);
  81.  
  82.     ResetWinDat();
  83.     ShowTitle( SurfScrn, 0L ); /* hide screen title behind backdrop */
  84.  
  85.     InitArea( &PolyInfo, PolyArea, 5);
  86.     rp->AreaInfo = &PolyInfo;
  87.  
  88.     PolyWorkSpace = AllocRaster( SurfWinDef.Width, SurfWinDef.Height);
  89.  
  90.     if( !PolyWorkSpace ) {
  91.         CloseDisplay();
  92.         perror("no space for temporary rastern");
  93.         exit(0);
  94.     }
  95.     else {
  96.         InitTmpRas( &PolyTmpRas, PolyWorkSpace,
  97.                     RASSIZE( SurfWinDef.Width, SurfWinDef.Height ));
  98.         rp->TmpRas = &PolyTmpRas;
  99.     }
  100. }
  101.  
  102.  
  103. void InitWindow()
  104. {
  105.     GfxBase = OpenLibrary("graphics.library",0);
  106.     if( GfxBase == 0 ) {
  107.         OutErr("graphics library won't open");
  108.         exit(10);
  109.     }
  110.  
  111.     IntuitionBase = OpenLibrary("intuition.library",0);
  112.     if( IntuitionBase == 0 ) {
  113.         OutErr("intuition library won't open");
  114.         exit(10);
  115.     }
  116.  
  117.     InitGadgets();
  118.     CntrlWin = OpenWindow( &CntrlWinDef );
  119.     CntrlSigBit = CntrlWin->UserPort->mp_SigBit;
  120.  
  121.     MenuSetScrn();
  122.  
  123.     if( !SurfScrn || !SurfWin || !CntrlWin ) {
  124.         OutErr("couldn't open at least one window or screen");
  125.         CloseDisplay();
  126.         exit( 0 );
  127.     }
  128.  
  129.     SetMenuStrip(CntrlWin, menu );
  130. }
  131.  
  132.  
  133. /*
  134.  * remove surface window/screen
  135.  */
  136. CloseSurf() {
  137.  
  138.     if( PolyWorkSpace)
  139.         FreeRaster( PolyWorkSpace, SurfWinDef.Width, SurfWinDef.Height );
  140.  
  141.     if( SurfWin )
  142.         CloseWindow( SurfWin );
  143.  
  144.     if( GadWin )
  145.         CloseWindow( GadWin );
  146.  
  147.     if( SurfScrn )
  148.         CloseScreen( SurfScrn );
  149. }
  150.  
  151.  
  152. void CloseDisplay()
  153. {
  154.  
  155.     CloseSurf();
  156.  
  157.  
  158.     if( CntrlWin ) {
  159.         ClearMenuStrip( CntrlWin );
  160.         CloseWindow( CntrlWin );
  161.     }
  162.  
  163.     EndGadgets();
  164.  
  165.     if ( IntuitionBase )
  166.         CloseLibrary(IntuitionBase);
  167.  
  168.     if ( GfxBase )
  169.         CloseLibrary(GfxBase);
  170. }
  171.  
  172.  
  173.